import { Map } from 'immutable';

import * as actionTypes from './constants';
import { actionType } from './s_mark'
import storage from '../../../../utils/storage'
const { session } = storage

const defaultState: Map<string, string | object> = Map({
  user: session?.get?.('userData') || {},
  token: session?.get?.('token') || '',
  userRoute: []

})

export default function reducer(state = defaultState, action: actionType) {
  const { payload, type } = action
  switch (type) {
    case actionTypes.LOGIN:
      return state.set("user", payload).set('token', payload.token);
    case actionTypes.LOGOUT:
      return state.set("user", {}).set('token', '');
    case actionTypes.ROUTE_ARY:
      return state.set("userRoute", payload);
    default:
      return state;
  }
}